package controller

import (
	"github.com/gin-gonic/gin"
	"net/http"
	"user_manger_go/entity"
	"user_manger_go/service"
)

type UserController struct {
	userService service.UserService
}

func NewUserController(userService service.UserService) *UserController {
	return &UserController{
		userService: userService,
	}
}

func (userController *UserController) GetUsers(c *gin.Context) {
	users := userController.userService.GetUsers()
	c.JSON(http.StatusOK, users)
}

func (userController *UserController) InsertUser(c *gin.Context) {
	userEntity := entity.User{}
	c.BindJSON(&userEntity)
	record := userController.userService.InsertUser(userEntity)
	c.JSON(http.StatusOK, record)
}
